Tailwind CSS 4.1 Three-Column Full Screen Layout
To achieve a three-column layout that fills the entire page height, we need to ensure both the outer container and each column have 100% height. In Tailwind CSS 4.1, follow these steps:
Set the root elements (
html
,body
) toheight: 100%
to allow subsequent elements to expand based on viewport height.Use flexbox layout with the outer container (flex container) set to viewport height (
h-screen
).Configure three flex columns: fixed-width left/right columns, a fluid center column, and automatic height stretching (default
align-items: stretch
ensures equal height).
Core Code:
Full Height Three Columns
Fixed width (256px)
Fluid width
Fixed width (256px)
Implementation Principles:
Set root elements to 100% height:
h-full
class (equivalent toheight: 100%
) makes the body fill the viewport height.Outer container settings:
flex
: Enables flexbox layouth-screen
: Sets container height to viewport height (100vh)
Column height behavior: Flexbox's default
align-items: stretch
automatically expands column heights to match the container's height (full screen). No manual height required.Fixed-width columns:
w-64
: Fixed width of 256pxshrink-0
: Prevents column shrinkage when space is limited
Fluid center column:
flex-1
: Occupies all remaining available space
Important Notes:
If content exceeds a column's height: Columns will expand (due to
align-items: stretch
), causing scrollbars. For internal scrolling, addoverflow-auto
to a nested container within the column.For non-fullscreen layouts: Ensure the parent container has explicit height, then set the layout container to
flex h-full
to inherit the parent's height.